//
//  ReviewResultsViewController.m
//  HappilyLoan
//
//  Created by 纵情向前 on 2017/4/22.
//  Copyright © 2017年 zongqingxiangqian. All rights reserved.
//

#import "ReviewResultsViewController.h"
#import "ZFHomeViewController.h"
#import "PublicClass.h"
#import "ZFHeader.h"
@interface ReviewResultsViewController ()<UIWebViewDelegate,UIScrollViewDelegate>
@property (nonatomic, strong)UIView *NavView;//导航
@property (nonatomic,strong) UIView *upView;
@property (nonatomic,strong) UIWebView *webView;
@property (nonatomic,strong) UILabel *upTitleLabel;
@property (nonatomic,assign) CGFloat contentOffsetY;
@property (nonatomic,strong) AnimatingView *anima;
@end

@implementation ReviewResultsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
    
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, ADAPTATION_HEIGHT(100), SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.webView.backgroundColor = [UIColor whiteColor];
    self.webView.scalesPageToFit = YES;
    self.webView.delegate = self;
    self.webView.scrollView.delegate = self;
    [self.view addSubview:self.webView];
    
    [self getArticleInfo];
    

    self.anima = [[AnimatingView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.upView addSubview:self.upTitleLabel];
    
    [self.view addSubview:self.upView];
    //Cell图片
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(0,0,MAINSCREEN_WIDTH,ADAPTATION_HEIGHT(5));
    label.backgroundColor = [UIColor lightGrayColor];
    [_upView addSubview:label];
    //Cell图片
    UILabel *otherLabel = [[UILabel alloc] init];
    otherLabel.frame = CGRectMake(0,ADAPTATION_HEIGHT(90),MAINSCREEN_WIDTH,ADAPTATION_HEIGHT(5));
    otherLabel.backgroundColor = [UIColor lightGrayColor];
    [_upView addSubview:otherLabel];
    
    // Do any additional setup after loading the view from its nib.
}
- (void)getArticleInfo{
    NSURL *url = [NSURL URLWithString:[_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *requst = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:requst];
//    [self.webView loadHTMLString:_url baseURL:nil];
}
//导航
- (void)setNav{
    _NavView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375/W, 64)];
    _NavView.backgroundColor = Main_Color1;
    
    UILabel *NavLabel = [[UILabel alloc]init];
    NavLabel.bounds = CGRectMake(0, 0, 150, 30);
    NavLabel.center = CGPointMake(MAINSCREEN_WIDTH/2, 40);
    NavLabel.textAlignment = NSTextAlignmentCenter;
    NavLabel.textColor = [UIColor whiteColor];
    NavLabel.text = @"审核结果";
    NavLabel.font = [UIFont systemFontOfSize:20 weight:1];
    
    UIButton *NavButton = [UIButton buttonWithType:UIButtonTypeCustom];
    NavButton.frame = CGRectMake(10, 25, 30, 30);
    NavButton.backgroundColor = [UIColor clearColor];
    NavButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [NavButton setImage:[UIImage imageNamed:@"返回键"] forState:UIControlStateNormal];
    [NavButton addTarget:self action:@selector(navbackButton:) forControlEvents:UIControlEventTouchUpInside];
    [_NavView addSubview:NavButton];
    [_NavView addSubview:NavLabel];
    [self.view addSubview:self.NavView];
}
#pragma mark -- uiscrollView delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGPoint point = [scrollView.panGestureRecognizer velocityInView:self.view];
    //下滑为负 point的y
    //上滑为正
    //   NSLog(@"%@",NSStringFromCGPoint(point));
    
    if (point.y > 0) {
        // 下
        self.upView.hidden = YES;
        self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

        
    }else if (point.y < 0){
        self.upView.hidden = YES;
        // 上
    }
    
    
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    
    _contentOffsetY = scrollView.contentOffset.y;
    
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
   
//    _webView.scrollView.contentInset = UIEdgeInsetsMake(ADAPTATION_HEIGHT(64), 0, 0, 0);
    //    NSLog(@"开始加载");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    //    NSLog(@"加载完成");
    [_anima stopTheAnimation];
    self.upView.hidden = NO;
    
}

#pragma mark - 返回
- (void)navbackButton:(UIButton *)sender{
    
    for (UIViewController *VCHome in self.navigationController.viewControllers) {
        
        if ([VCHome isKindOfClass:[ZFHomeViewController class]]) {
            
            [self.navigationController popToViewController:VCHome animated:YES];
        }
    }
}
- (UIView *)upView{
    if (!_upView) {
        _upView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, ADAPTATION_HEIGHT(100))];
        _upView.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1];
        _upView.userInteractionEnabled = YES;
        
    }
    return _upView;
}
- (UILabel *)upTitleLabel {
    
    if (!_upTitleLabel) {
        _upTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ADAPTATION_WIDTH(((375-250)/2)),ADAPTATION_HEIGHT(15),ADAPTATION_WIDTH(250),ADAPTATION_HEIGHT(60))];
//        _upTitleLabel.center = self.upView.center;
        _upTitleLabel.font = [UIFont systemFontOfSize:16];
        _upTitleLabel.text = @"很遗憾，您的审核未通过\n我们精心为您准备了以下产品";
        _upTitleLabel.numberOfLines = 0;
        _upTitleLabel.backgroundColor = [UIColor clearColor];
        _upTitleLabel.textAlignment = NSTextAlignmentCenter;
        
    }
    return _upTitleLabel;
}
- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    self.upView.hidden = YES;
     [_anima startTheAnimation];
}
- (void)viewWillDisappear:(BOOL)animated{
    [_anima stopTheAnimation];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
